package pl.cba.solgar.game.rogal;

import java.util.Vector;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;

public class Room
{
	public Vector<Room> connections;

	public int x;
	public int y;
	public int w;
	public int h;

	public Room(int x, int y, int w, int h)
	{
		connections = new Vector<Room>();
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
	}

	public boolean hasConnectionToRoom(Room desiredRoom, Vector<Room> visitedRooms)
	{
		if (visitedRooms.contains(this))
			return false;
		else
			visitedRooms.add(this);

		if (desiredRoom == this)
			return true;

		for (Room connectedRoom : connections)
		{
			boolean hasConnection = connectedRoom.hasConnectionToRoom(desiredRoom, visitedRooms);
			if (hasConnection)
				return true;
		}
		return false;
	}

	public void debugPaint(Graphics g)
	{
		g.setColor(Color.red);
		g.drawRect(x*Rogal.FONT_WIDTH, y*Rogal.FONT_HEIGHT, w*Rogal.FONT_WIDTH, h*Rogal.FONT_HEIGHT);
		g.setColor(Color.green);
		for (Room room : connections)
		{
			g.drawLine((x + w/2)*Rogal.FONT_WIDTH, (y + h/2)*Rogal.FONT_HEIGHT, (room.x + room.w/2)*Rogal.FONT_WIDTH, (room.y + room.h/2)*Rogal.FONT_HEIGHT);
			g.fillRect((room.x + room.w/2)*Rogal.FONT_WIDTH - 4, (room.y + room.h/2)*Rogal.FONT_HEIGHT - 4, 8, 8);
		}
	}


}
